<!-- Author: Mary Llenos --> 
<!-- Last Modified: 11 Aug 2012 --> 
<!-- This checks if username and password entered from log in page is valid --> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php session_start();
if (!isset($_SESSION['username']))
	{
$db_name="onestopjcu"; // Database name
$tbl_name="member"; // Table name
 
$connection = mysql_connect("localhost", "root", "");
mysql_select_db("$db_name", $connection);

$myusername=mysql_real_escape_string($_POST['myusername']);
$mypassword=mysql_real_escape_string($_POST['mypassword']);
 
$sqlStr = "SELECT * FROM $tbl_name WHERE mem_email='$myusername' and mem_pword='$mypassword'";

$result=mysql_query($sqlStr);

$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
  // Register $myusername, $mypassword and redirect page
  $_SESSION['username'] = "$myusername";

//set SESSION variables required during logged in
while($row = mysql_fetch_array($result))
  {
  $name = $row['mem_fname'];
  $id = $row['mem_id'];
  }
  $_SESSION['visitor'] = $name;
  $_SESSION['msg'] = "Welcome, ".$_SESSION['username'];
  $_SESSION['visitorID'] = $id;
  header("location: home.php");

} 
	
// Check if session is not registered , redirect back to login page.
else
		{
			$_SESSION['msg'] = "Please Log-in to enjoy our services!";
			header("Location: register.php");
		}
}
?>
</body>
</html>